var express = require('express');
var router = express.Router();
var core = require('core');
var api = core.api.list;
var wechat = core.wechat;
var wapi = wechat.api.list;

router.get('/', function(req, res, next){
    res.render('tags/index', {});
});

router.get('/list', function(req, res, next){
    // console.log();
    wechat.api.list.user.tags({
        url : "get",
        tag: {
            name : req.body.tags
        }
    }, function(err, doc){
        res.render('tags/list', doc);
    });
});

router.get('/create', function(req, res, next){
    res.render('tags/create', {});
});

router.get('/user', function(req, res, next){
    wechat.api.list.user.tags({
        url : "getidlist",
        openid : req.query.openid
    }, function(err, doc){
        res.send(doc);
    });
});

router.get('/delete', function(req, res, next){
    var query = req.query;
    wechat.api.list.user.tags({
        url : "delete",
        tag: {
            id : query.id
        }
    }, function(err, doc){
        res.redirect('/tags/list');
    });
});

router.post('/create', function(req, res, next){
    wechat.api.list.user.tags({
        url : "create",
        tag : {
            name : req.body.tags
        }
    }, function(err, doc){
        console.log('-=-=====', err, doc);
        // if(!err)
            // console.log(doc);
    });
    res.send("success");
});

module.exports = router;
